/* GUI CONVERTED from reisrc04.p (converter v1.76) Tue Jun 25 15:49:47 2002 */
/* reisrc04.p - WORK ORDER RECEIPT W/ SERIAL NUMBERS FROM LABOR TRANSACTION  */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Revision: 1.9.1.9 $                                    */
/* REVISION: 6.0      LAST MODIFIED: 06/19/90   BY: emb                      */
/* REVISION: 6.0      LAST MODIFIED: 07/06/90   BY: EMB *D040                */
/* REVISION: 6.0      LAST MODIFIED: 07/24/90   BY: SMM *D072                */
/* REVISION: 6.0      LAST MODIFIED: 10/10/90   BY: SMM *D085                */
/* REVISION: 6.0      LAST MODIFIED: 03/18/91   BY: WUG *D472*               */
/* REVISION: 6.0      LAST MODIFIED: 04/08/91   BY: emb *D485*               */
/* REVISION: 6.0      LAST MODIFIED: 08/01/91   BY: emb *D805*               */
/* REVISION: 6.0      LAST MODIFIED: 10/03/91   BY: alb *D887*               */
/* REVISION: 7.0      LAST MODIFIED: 10/15/91   BY: pma *F003*               */
/* REVISION: 7.0      LAST MODIFIED: 01/28/92   BY: pma *F104*               */
/* REVISION: 7.0      LAST MODIFIED: 02/12/92   BY: pma *F190*               */
/* REVISION: 7.0      LAST MODIFIED: 02/21/92   BY: pma *F085*               */
/* REVISION: 7.0      LAST MODIFIED: 03/09/92   BY: smm *F230*               */
/* REVISION: 7.0      LAST MODIFIED: 07/21/92   BY: pma *F783*               */
/* Revision: 7.3          Last edit: 09/27/93   By: jcd *G247*               */
/* REVISION: 7.3      LAST MODIFIED: 11/03/92   BY: emb *G269*               */
/* REVISION: 7.3      LAST MODIFIED: 01/11/93   BY: emb *G689*               */
/* Oracle changes (share-locks)      09/12/94   BY: rwl *FR25*               */
/* REVISION: 7.3      LAST MODIFIED: 10/05/94   BY: pxd *FR90*               */
/* REVISION: 8.5      LAST MODIFIED: 11/28/94   BY: taf *J038*               */
/* REVISION: 8.5      LAST MODIFIED: 01/05/95   BY: pma *J040*               */
/* REVISION: 8.5      LAST MODIFIED: 04/23/95   BY: sxb *J04D*               */
/* REVISION: 7.2      LAST MODIFIED: 08/17/95   BY: qzl *F0TC*               */
/* REVISION: 8.5      LAST MODIFIED: 12/03/95   BY: sxb *J053*               */
/* REVISION: 8.6      LAST MODIFIED: 03/15/97   BY: *K04X* Steve Goeke       */
/* Old ECO marker removed, but no ECO header exists *F0PN*                   */
/* Old ECO marker removed, but no ECO header exists *K1Q4*                   */
/* REVISION: 8.6E     LAST MODIFIED: 06/29/98   BY: *L034* Markus Barone     */
/* REVISION: 8.6E     LAST MODIFIED: 03/25/99   BY: *J39K* Sanjeev Assudani  */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Murali Ayyagari   */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Steve Nugent      */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb               */
/* REVISION: 9.1      LAST MODIFIED: 09/25/00   BY: *N0WD* BalbeerS Rajput   */
/* Revision: 1.9.1.6  BY: Niranjan R.    DATE: 07/13/01  ECO: *P00L*         */
/* Revision: 1.9.1.7  BY: Ellen Borden   DATE: 04/03/01  ECO: *P00G*         */
/* Revision: 1.9.1.8  BY: Jeff Wootton   DATE: 05/14/02  ECO: *P03G*         */
/* $Revision: 1.9.1.9 $  BY: Jeff Wootton   DATE: 06/03/02  ECO: *P079* */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/*V8:ConvertMode=Maintenance                                                 */

/* DECLARE COMMON VARIABLES */
{mfdeclre.i}
{cxcustom.i "REISRC04.P"}

define new shared variable wo_recno as recid.
define variable rpsnbr like mrp_nbr.
define variable rpsrecord like rps_record.
define buffer rpsmstr for rps_mstr.

define shared variable wo_recid as recid.
define shared variable ophist_recid as recid.

define variable rmks like tr_rmks.
define new shared variable ref like glt_ref.
define variable i as integer.
define variable null_ch as character initial "".
define new shared variable eff_date like glt_effdate.
define variable qty_left like op_qty_comp.
define shared variable site like rps_site no-undo.
define variable cr_acct like wo_acct.
define variable cr_sub like wo_sub.
define variable cr_cc like wo_cc.
define variable gl_amt like glt_amt.
define variable glcost like sct_cst_tot.
define variable gl_cost like sct_cst_tot.
define new shared variable transtype as character format "x(7)".
define new shared variable sf_cr_acct like dpt_lbr_acct.
define new shared variable sf_dr_acct like dpt_lbr_acct.
define new shared variable sf_cr_sub like dpt_lbr_sub.
define new shared variable sf_dr_sub like dpt_lbr_sub.
define new shared variable sf_cr_cc like dpt_lbr_cc.
define new shared variable sf_dr_cc like dpt_lbr_cc.
define new shared variable sf_gl_amt like tr_gl_amt.
define new shared variable sf_entity like en_entity.
define variable assay like tr_assay.
define variable grade like tr_grade.
define variable expire like tr_expire.
/* Added section */
define variable newmtl_tl as decimal.
define variable newlbr_tl as decimal.
define variable newbdn_tl as decimal.
define variable newovh_tl as decimal.
define variable newsub_tl as decimal.
define variable newmtl_ll as decimal.
define variable newlbr_ll as decimal.
define variable newbdn_ll as decimal.
define variable newovh_ll as decimal.
define variable newsub_ll as decimal.
define variable newcst as decimal.
define variable glx_mthd like cs_method.
define variable glx_set like cs_set.
define variable cur_mthd like cs_method.
define variable cur_set like cs_set.
define variable reavg_yn as logical.
define variable qty_chg like tr_qty_loc.
define variable msgref like tr_msg.
/* End of added section */
define shared variable prline like rps_line no-undo.
define new shared variable tr_recno as recid.
define variable trans-ok like mfc_logical.
define variable gl_tmp_amt as decimal no-undo.
{&REISRC04-P-TAG1}
define shared variable h_wiplottrace_procs as handle no-undo.
define shared variable h_wiplottrace_funcs as handle no-undo.
define variable optrnbr as integer no-undo.
define variable ophistrecid as recid no-undo.
define buffer ophist for op_hist.
define variable temp_recid as recid no-undo.
define variable iss_trnbr like tr_trnbr no-undo.
define variable rct_trnbr like tr_trnbr no-undo.

{wlfnc.i} /*FUNCTION FORWARD DECLARATIONS*/
{wlcon.i} /*CONSTANTS DEFINITIONS*/

/*DEFINE VARIABLES FOR CHANGE ATTRIBUTES FEATURE*/
{gpatrdef.i "shared"}

find first clc_ctrl no-lock no-error.
if not available clc_ctrl then do:
   {gprun.i ""gpclccrt.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

   find first clc_ctrl no-lock.
end.

find op_hist no-lock where recid(op_hist) = ophist_recid no-error.
eff_date = op_date.

find wo_mstr where recid(wo_mstr) = wo_recid no-error.
if available wo_mstr then do:

   wo_qty_chg = 0.

   find first gl_ctrl no-lock no-error.

   find pt_mstr where pt_part = wo_part no-lock.
   find pl_mstr where pl_prod_line = pt_prod_line no-lock.

   if wo_acct <> "" then
   assign
      cr_acct = wo_acct
      cr_sub  = wo_sub
      cr_cc   = wo_cc.
   else do:
      {gprun.i ""glactdft.p"" "(input ""WO_WIP_ACCT"",
                                          input pt_prod_line,
                                          input wo_site,
                                          input """",
                                          input """",
                                          input no,
                                          output cr_acct,
                                          output cr_sub,
                                          output cr_cc)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   end. /* IF WO_ACCT = " " */

   transtype = "RCT-WO".

   /*DETERMINE COSTING METHOD*/
   {gprun.i ""csavg01.p""
      "(input wo_part, input wo_site,
              output glx_set, output glx_mthd,
              output cur_set, output cur_mthd)" }
/*GUI*/ if global-beam-me-up then undo, leave.


   /*UPDATE CURRENT COST & POST ANY GL DISCREPANCY*/
   /*CALCULATE AMOUNTS TO AVERAGE BY COST CATEGORY*/
   if glx_mthd = "AVG" or cur_mthd = "AVG" or cur_mthd = "LAST"
   then do:
      for each sr_wkfl exclusive-lock where sr_userid = mfguser

            and sr_lineid = "+" + wo_part:
         qty_chg = qty_chg + sr_qty.
      end.
      {gprun.i ""csavg02.p""
         "(input wo_part,
           input wo_site,
           input transtype,
           input 0,
           input recid(wo_mstr),
           input wo_nbr,
           input qty_chg,
           input 0,
           input glx_set,
           input glx_mthd,
           input cur_set,
           input cur_mthd,
           output newmtl_tl,
           output newlbr_tl,
           output newbdn_tl,
           output newovh_tl,
           output newsub_tl,
           output newmtl_ll,
           output newlbr_ll,
           output newbdn_ll,
           output newovh_ll,
           output newsub_ll,
           output newcst,
           output reavg_yn,
           output msgref)" }
/*GUI*/ if global-beam-me-up then undo, leave.

   end.

   {gpsct01.i &set=glx_set &part=pt_part &site=wo_site}
   if glx_mthd = "AVG" then glcost = newcst.
   else glcost = sct_cst_tot.

   for each sr_wkfl where sr_userid = mfguser

         and sr_lineid = "+" + wo_part:
/*GUI*/ if global-beam-me-up then undo, leave.

      gl_amt = glcost * sr_qty.
      /* ROUND RECEIVED COST TO BASE CURRENCY PRECISION */
      {gprun.i ""gpcurrnd.p"" "(input-output gl_amt,
                                         input gl_rnd_mthd)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      find ld_det where ld_site = sr_site
         and ld_loc = sr_loc
         and ld_part = pt_part
         and ld_lot = sr_lotser
         and ld_ref = sr_ref
         no-lock no-error.
      if available ld_det then do:
         assay = ld_assay.
         grade = ld_grade.
         expire = ld_expire.
      end.

      /*RE-CALCULATE AVERAGE COST*/
      if glx_mthd = "AVG" and reavg_yn then do:
         {gprun.i ""csavg03.p""
            "(input recid(sct_det), input sr_qty,
                  input newmtl_tl, input newlbr_tl,
                  input newbdn_tl, input newovh_tl,
                  input newsub_tl, input newmtl_ll,
                  input newlbr_ll, input newbdn_ll,
                  input newovh_ll, input newsub_ll)" }
/*GUI*/ if global-beam-me-up then undo, leave.

      end.

      if (clc_lotlevel <> 0) and (sr_lotser <> "") then do:
         {gprun.i ""gpiclt.p"" "(input wo_part,
                                          input sr_lotser,
                                          input wo_nbr,
                                          input wo_lot,
                                          output trans-ok)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         if not trans-ok then do:
            {pxmsg.i &MSGNUM=2740 &ERRORLEVEL=4}
            /* CURRENT TRANSACTION REJECTED - */
            undo, next.        /* CONTINUE WITH NEXT TRANSACTION */
         end. /* IF NOT TRANS-OK */
      end. /* IF (CLC_LOTLEVEL <> 0) */

      /* ADDED SECOND EXCHANGE RATE, TYPE, SEQUENCE */
      /* ADDED CRSUB AND DRSUB BELOW */
      {ictrans.i
         &addrid=wo_vend
         &bdnstd=0
         &cracct=cr_acct
         &crsub=cr_sub
         &crcc=cr_cc
         &crproj="
                     if wo_acct <> """" then
                        wo_project
                     else
                        """""
         &curr=""""
         &dracct="
                     if available pt_mstr then
                        if available pld_det then pld_inv_acct
                        else pl_inv_acct
                     else gl_inv_acct"
         &drsub="
                     if available pt_mstr then
                        if available pld_det then pld_inv_sub
                        else pl_inv_sub
                     else gl_inv_sub"
         &drcc="
                     if available pt_mstr then
                        if available pld_det then pld_inv_cc
                        else pl_inv_cc
                     else gl_inv_cc"
         &drproj="
                     if wo_acct <> """" then
                        wo_project
                     else
                        """""
         &effdate=eff_date
         &exrate=0
         &exrate2=0
         &exratetype=""""
         &exruseq=0
         &glamt=gl_amt
         &lbrstd=0
         &line=0
         &location="(if sr_site <> wo_site then pt_loc
                              else sr_loc)"
         &lotnumber=wo_lot
         &lotserial=sr_lotser
         &lotref=sr_ref
         &mtlstd=0
         &ordernbr=wo_nbr
         &ovhstd=0
         &part=wo_part
         &perfdate=?
         &price=glcost
         &quantityreq="wo_qty_ord - wo_qty_comp - wo_qty_rjct"
         &quantityshort=wo_bo_chg
         &quantity="sr_qty"
         &revision=""""
         &rmks=rmks
         &shiptype=""""
         &site=wo_site
         &slspsn1=""""
         &slspsn2=""""
         &sojob=wo_so_job
         &substd=0
         &transtype=""RCT-WO""
         &msg=msgref
         &ref_site=tr_site
         }

      wo_qty_chg = wo_qty_chg + sr_qty.
      wo_wip_tot = wo_wip_tot - gl_amt.
      tr_recno = recid(tr_hist).

      if glx_mthd = "AVG" then trgl_type = "RCT-AVG".
      if sr_site <> wo_site then do:

         global_part = wo_part.
         global_addr = wo_vend.

         {gprun.i ""icxfer.p"" "(wo_lot,
                                          sr_lotser,
                                          sr_ref,
                                          sr_ref,
                                          sr_qty,
                                          wo_nbr,
                                          wo_so_job,
                                          rmks,
                                          wo_project,
                                          eff_date,
                                          wo_site,
                                          pt_loc,
                                          sr_site,
                                          sr_loc,
                                          no,
                                          """",
                                          ?,
                                          """",
                                          0,
                                          output gl_cost,
                                          output iss_trnbr,
                                          output rct_trnbr,
                                          input-output assay,
                                          input-output grade,
                                          input-output expire)" }
/*GUI*/ if global-beam-me-up then undo, leave.


         /*CHANGE ATTRIBUTES*/
         find tr_hist no-lock where tr_trnbr = trmsg no-error.
      end.

      /*CHANGE ATTRIBUTES*/
      if available tr_hist then do:
         /* ADDED FIFTH PARAMETER EFF_DATE */
         {gprun.i ""worcat03.p"" "(input recid(sr_wkfl),
                                            input recid(tr_hist),
                                            input tr_recno,
                                            input wo_part,
                                            input eff_date,
                                            input-output chg_assay,
                                            input-output chg_grade,
                                            input-output chg_expire,
                                            input-output chg_status,
                                            input-output assay_actv,
                                            input-output grade_actv,
                                            input-output expire_actv,
                                            input-output status_actv)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      end.

      for first op_hist where recid(op_hist) = ophist_recid
            no-lock:
      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      if is_wiplottrace_enabled()
         and is_operation_queue_lot_controlled
         (op_wo_lot, op_wo_op, OUTPUT_QUEUE)
         and index(program-name(2), 'reoptr13') = 0
      then do:
         /*DO THE EQUIVALENT OF A MOVE TO FINISHED MATL INVENTORY*/

         {gprun.i ""reophist.p"" "(input op_type,
                  input op_wo_lot, input op_wo_op, input op_emp,
                  input op_wkctr, input op_mch, input op_dept, input op_shift,
                  input op_date,
                  output temp_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         /*CONSUME A WIPLOT IN THE OUTPUT QUEUE OF THE
         /*N002*/          SAME LOT AND REF AS WHAT WILL BE RECEIVED*/

         for first op_hist where recid(op_hist) = temp_recid
               exclusive-lock:
         end.

         run consume_wip_lot
            in h_wiplottrace_procs
            (
            input op_wo_lot,
            input op_wo_op,
            input sr_lotser,
            input sr_ref,
            input wo_site,
            input op_wkctr,
            input op_mch,
            input op_wo_lot,
            input op_wo_op,
            input OUTPUT_QUEUE,
            input sr_qty,
            input op_trnbr).

         /*REGISTER THE FINISHED MATERIAL RECEIVED
         /*N002*/          IN THE TRACING JOURNAL*/

         run add_trace_record
            in h_wiplottrace_procs
            (
            input OPERATION_HISTORY,
            input op_trnbr,
            input PRODUCED_MTL,
            input ITEM_MTL,
            input '',
            input 0,
            input wo_part,
            input sr_lotser,
            input '',
            input sr_qty).
      end.

      delete sr_wkfl.
   end.  /*for each sr_wkfl*/
   {gprun.i ""gplotwdl.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

   /*DEBIT WIP & CREDIT MFG APPLIED OVHD FOR OVERHEAD THIS LEVEL*/
   wo_recno = recid(wo_mstr).
   {gprun.i ""woovhd.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


   /* UPDATE CUMULATIVE WORK ORDER */

   wo_qty_comp = wo_qty_comp + wo_qty_chg.
   wo_qty_ord  = wo_qty_comp + wo_qty_rjct.
   wo_qty_chg = 0.
   wo_bo_chg = 0.
   wo_rjct_chg = 0.

   /* UPDATE VARIANCES AT RECEIPT */
   if glx_mthd <> "AVG" then do:
      transtype = "VAR-POST".
      {gprun.i ""wovarup.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

   end.
end. /*if available wo_mstr*/

/* End of deleted section*/
